#pragma once

#include <AVUIItemStructMap.h>
#include <AVUIItemStructList.h>
#include <AVUIUIString.h>

namespace AVUI {

class EventHandlersStore;
class TriggerActionCollection;
class TriggerBase;

class BindingValueCache : public Object
{
public:
    BindingValueCache(const Type* pBindingValueType, Object* pValueAsBindingValueType) : BindingValueType(pBindingValueType), ValueAsBindingValueType(pValueAsBindingValueType) { }

    const Type* BindingValueType;
    TRefCountedPtr<Object> ValueAsBindingValueType;
};


struct TriggerCondition
{
    TriggerCondition() : LogicalOp(LogicalOp::Equals), pProperty(NULL), SourceChildIndex(0) {}
    TriggerCondition(BindingBase* pBinding, LogicalOp::Enum logicalOp, Object* pValue);
    TriggerCondition(BindingBase* pBinding, LogicalOp::Enum logicalOp, Object* pValue, String* pSourceName);
    TriggerCondition(DependencyProperty* pDP, LogicalOp::Enum logicalOp, Object* pValue, String* pSourceName);

    bool ConvertAndMatch(Object* pState);
    bool Match(Object* pState) { return Match(pState, Value); }
    bool Match(Object* pState, Object* pReferenceValue);
    bool TypeSpecificEquals(TriggerCondition* pValue);

    TRefCountedPtr<BindingBase> Binding;
    TRefCountedPtr<BindingValueCache> BindingValueCache;
    LogicalOp::Enum LogicalOp;
    DependencyProperty* pProperty;
    int SourceChildIndex;
    TRefCountedPtr<String> SourceName;
    TRefCountedPtr<Object> Value;
};

struct ContainerDependent
{
    ContainerDependent() : FromVisualTrigger(false), pProperty(NULL) { }
    bool FromVisualTrigger;
    DependencyProperty* pProperty;
};

struct ChildValueLookup
{
    ChildValueLookup() : LookupType(ValueLookupType::Simple), pProperty(NULL) { }
    TArrayPtr<TriggerCondition> Conditions;
    ValueLookupType::Enum LookupType;
    DependencyProperty* pProperty;
    ObjectPtr Value;
};

struct PropertyValue
{
    PropertyValue() : pProperty(NULL), ValueType(PropertyValueType::Set) { }
    Object* get_Value();

    StringPtr ChildName;
    TArrayPtr<TriggerCondition> Conditions;
    DependencyProperty* pProperty;
    ObjectPtr ValueInternal;
    PropertyValueType::Enum ValueType;
};

struct ChildPropertyDependent
{
    ChildPropertyDependent() : ChildIndex(0), pProperty(NULL) { }
    int ChildIndex;
    DependencyProperty* pProperty;
    TRefCountedPtr<Object> Name;
};

class EventHandlersStore;
struct ChildEventDependent
{
    ChildEventDependent() : ChildIndex(0) { }
    int ChildIndex;
    TWeakPtr<EventHandlersStore> EventHandlersStore;
};

struct TriggerSourceRecord
{
    ItemStructList<ChildPropertyDependent> ChildPropertyDependents;
};

struct ChildRecord
{
public:
    ItemStructMap< ItemStructList<ChildValueLookup> > ValueLookupListFromProperty;
};

struct DeferredAction
{
    TRefCountedPtr<TriggerActionCollection> TriggerActionCollection;
    TRefCountedPtr<TriggerBase> TriggerBase;
};

class DataTriggerRecord : public Object
{
public:
    DECLARE_ELEMENT(DataTriggerRecord, Object);

    ItemStructList<ChildPropertyDependent> Dependents;
};

 


}; // namespace AVUI
